var amapFile = require('../amap/amap-wx.130.js') //引入高德地图插件
var myAmapFun = new amapFile.AMapWX({
	key: '18ff0e7118fa6cc2d54ff64ebcc96dda' //请配置高德key
});

/**获取地址解析
 * @param {String} location  -经纬度 非必填 格式为'longitude,latitude'
 **/
function getRegeo(location = '') {
	return new Promise((reject, resolve) => {
		myAmapFun.getRegeo({
			location,
			success: function(data) {
				reject(data[0])
			},
			fail: function(error) {
				resolve(error)
			}
		})
	})
}

//获取天气预报
function getWeather(cityCode = '') {
	var weeks = ['周一', '周二', '周三', '周四', '周五', '周六', '星期天']
	var weatherList = []
	return new Promise((reject, resolve) => {
		myAmapFun.getWeather({
			type: 'forecast',
			city: cityCode,
			success: res => {
				weatherList = res.forecast.casts.map(item => {
					if (item.week == new Date().getDay()) item.week = '今天'
					else item.week = weeks[item.week * 1-1]
					return item
				})
				reject(weatherList)
			},
			fail: function(error) {
				resolve(error)
			}
		})
	})
}



export default {
	getRegeo,
	getWeather,
}
